home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 235_02 / ovtag.c < prev    next >
Text File  |  1987-06-16  |  14KB  |  444 lines

  1. /*  019  14-Feb-87  ovtag.c
  2.  
  3.         Copyright (c) 1987 by Blue Sky Software.  All rights reserved.
  4. */
  5.  
  6. #include "ov.h"
  7.  
  8. #ifndef NULL
  9. #define NULL (0)
  10. #endif
  11.  
  12. static char *name;                     /* wildcard (maybe) name to tag */
  13. static unsigned char attrib;           /* attribute to tag by */
  14. static unsigned from_date, to_date;    /* dates to use in tag by date */
  15. static unsigned from_time, to_time;    /* times to use in tag by time */
  16.  
  17. #define TDROWS 10                      /* box constants used by tag_date */
  18. #define TDCOLS 32
  19. #define TDFROW (FIRST_NROW+3)
  20. #define TDFCOL 24
  21.  
  22. static struct {        /* defines fields used by tag by date/time */
  23.    char row;
  24.    char col;
  25.    char len;
  26.    char value[9];
  27. } tdflds[] = { { TDFROW+4, TDFCOL+7, 8, "" },
  28. { TDFROW+4, TDFCOL+16, 8, "00:00:00" }, { TDFROW+4, TDFCOL+27, 1, "A" },
  29. { TDFROW+6, TDFCOL+7, 8, "" }, { TDFROW+6, TDFCOL+16, 8, "12:00:00" },
  30. { TDFROW+6, TDFCOL+27, 1, "P" } };
  31.  
  32. unsigned int cvtdate(), cvttime();
  33.  
  34. static struct {                /* used to check/convert time/date fields */
  35.    int *cvtresult;
  36.    int (*cvtrtn)();
  37.    char *p1, *p2;
  38.    char *name;
  39. } cvtflds[] = {
  40.    { &from_date, cvtdate, tdflds[0].value, NULL, "from date" },
  41.    { &to_date, cvtdate, tdflds[3].value, NULL, "to date" },
  42.    { &from_time, cvttime, tdflds[1].value, tdflds[2].value, "from time" },
  43.    { &to_time, cvttime, tdflds[4].value, tdflds[5].value, "to time" } };
  44.  
  45. int by_name(), by_date(), by_attrib();
  46.  
  47. extern struct window cw;
  48. extern struct file_ent files[];
  49.  
  50. unsigned int getdate();
  51. char *strupr(), *mmddyy();
  52.  
  53.  
  54. /******************************************************************************
  55.  **                       T A G _ C U R R E N T                              **
  56.  *****************************************************************************/
  57.  
  58. tag_current() {        /* toggle the tag state of the current file */
  59.  
  60.    tag_toggle(&files[cw.curidx],cw.curidx);  /* toggle the current file */
  61.  
  62.    disp_file_stats();                  /* display (maybe) updated file stats */
  63. }
  64.  
  65.  
  66. /******************************************************************************
  67.  **                      T A G _ M O D I F I E D                             **
  68.  *****************************************************************************/
  69.  
  70. tag_modified() {       /* tag files with the archive attriute set */
  71.  
  72.    attrib = ARCHIVE;                   /* tag files with this attribute */
  73.  
  74.    tag_files(by_attrib);               /* tag'em an' flag'em */
  75. }
  76.  
  77.  
  78. /******************************************************************************
  79.  **                         T A G _ N A M E                                  **
  80.  *****************************************************************************/
  81.  
  82. tag_name() {           /* wildcard tag of files by name */
  83.  
  84.    name = strupr(prompt("Tag by name","File name pattern: ",
  85.           NULL,0,12));
  86.  
  87.    if (strlen(name) == 0)
  88.       return;
  89.  
  90.    tag_files(by_name);                         /* tag all matchting files */
  91. }
  92.  
  93.  
  94. /******************************************************************************
  95.  **                         T A G _ D A T E                                  **
  96.  *****************************************************************************/
  97.  
  98. tag_date() {
  99.  
  100.    int cvterr;
  101.    register int i;
  102.    char *tmp, *boxsave;
  103.    unsigned char quit = 0;
  104.  
  105.    /* display the tag by date dialog box */
  106.  
  107.    boxsave = (char *) Malloc(TDROWS * TDCOLS * 2);
  108.  
  109.    setvattrib(DIS_BOX);
  110.    popup(TDFROW,TDFCOL,TDROWS,TDCOLS,boxsave);
  111.  
  112.    disp_str_at(" Tag by Date/Time ",TDFROW,TDFCOL+2);  /* display box title */
  113.  
  114.    disp_str_at("MM/DD/YY HH:MM:SS Am/Pm",TDFROW+2,TDFCOL+7);   /* box text */
  115.    disp_str_at("From",TDFROW+4,TDFCOL+2);
  116.    disp_str_at("To",TDFROW+6,TDFCOL+2);
  117.  
  118.    setvattrib(DIS_HIBOX);
  119.    disp_str_at("Press ESC to Quit",TDFROW+8,TDFCOL+7);
  120.  
  121.    if (strlen(tdflds[0].value) == 0) {         /* default to todays date */
  122.       tmp = mmddyy(getdate());
  123.       strcpy(tdflds[0].value,tmp);
  124.       strcpy(tdflds[3].value,tmp);
  125.    }
  126.  
  127.    /* display the input fields and default values */
  128.  
  129.    for (i = 0; i < 6; i++)
  130.       disp_str_at(tdflds[i].value,tdflds[i].row,tdflds[i].col);
  131.  
  132.    /* read the field values from user */
  133.  
  134.    for (i = 0; i < 6; i++) {
  135.       gotorc(tdflds[i].row,tdflds[i].col);
  136.       if (strlen(tmp = read_str(tdflds[i].len,tdflds[i].value,0)))
  137.          strcpy(tdflds[i].value,tmp);
  138.  
  139.       else {                   /* quit if nothing read */
  140.          quit = 1;
  141.          break;
  142.       }
  143.    }
  144.  
  145.    setvattrib(DIS_NORM);
  146.  
  147.    /* convert ascii date/times to file date/time formats */
  148.  
  149.    if (!quit)
  150.       for (i = 0; i < 4; i++) {
  151.          *cvtflds[i].cvtresult = (*cvtflds[i].cvtrtn)(cvtflds[i].p1,
  152.                                                       cvtflds[i].p2,&cvterr);
  153.          if (cvterr) {
  154.             show_error(0,0,2,"Invalid ",cvtflds[i].name);
  155.             quit = 1;
  156.          }
  157.       }
  158.  
  159.    /* get rid of the display box */
  160.  
  161.    popdwn(TDFROW,TDFCOL,TDROWS,TDCOLS,boxsave);
  162.    free(boxsave);
  163.  
  164.    /* finally tag the files */
  165.  
  166.    if (!quit)
  167.       tag_files(by_date);
  168.  
  169. }
  170.  
  171.  
  172. /******************************************************************************
  173.  **                         T A G _ I N V E R T                              **
  174.  *****************************************************************************/
  175.  
  176. tag_invert() {         /* invert the tag state of all files */
  177.  
  178.    register int i;
  179.    register struct file_ent *fp;
  180.  
  181.    fp = files;
  182.    for (i = 0; i < cw.nfiles; i++, fp++)
  183.       tag_toggle(fp,i);
  184.  
  185.    disp_file_stats();                          /* disp updated stats */
  186.  
  187. }
  188.  
  189.  
  190. /******************************************************************************
  191.  **                         T A G _ R E S E T                                **
  192.  *****************************************************************************/
  193.  
  194. tag_reset() {          /* clear all tagged file indicators */
  195.  
  196.    register int i;
  197.    register struct file_ent *fp;
  198.  
  199.    fp = files;
  200.    for (i = 0; i < cw.nfiles; i++, fp++)
  201.       if (fp->flags & TAGGED) {
  202.          fp->flags &= ~TAGGED;
  203.          if (on_screen(i)) {
  204.             gotorc(idx2sr(i),idx2sc(i));
  205.             disp_file(fp,i == cw.curidx);
  206.          }
  207.       }
  208.  
  209.    cw.num_tagged = 0;                          /* no files tagged now */
  210.    cw.tag_size = 0;
  211.    disp_file_stats();                          /* disp updated (0) stats */
  212.  
  213. }
  214.  
  215.  
  216. /******************************************************************************
  217.  **                         T A G _ T O D A Y                                **
  218.  *****************************************************************************/
  219.  
  220. tag_today() {          /* tag all files created/modified today */
  221.  
  222.    from_date = to_date = getdate();
  223.    from_time = 0;
  224.    to_time = 0xffff;
  225.  
  226.    tag_files(by_date);
  227. }
  228.  
  229.  
  230. /******************************************************************************
  231.                           T A G _ F I N D
  232.  *****************************************************************************/
  233.  
  234. tag_find(dir)          /* find (goto) the next or perv tagged file */
  235. int dir;
  236. {
  237.    register int i;
  238.  
  239.    if (cw.num_tagged == 0)             /* nowhere to go if no files tagged */
  240.       return;
  241.  
  242.    /* find the next (prev) tagged file */
  243.  
  244.    i = cw.curidx;
  245.    do {
  246.       i += dir;                        /* move forward or backward */
  247.       if (i >= cw.nfiles)              /* gotta watch for wrap arounds */
  248.          i = 0;
  249.       else
  250.          if (i < 0)
  251.             i = cw.nfiles - 1;
  252.    } while ((files[i].flags & TAGGED) == 0);   /* done if at a tagged file */
  253.  
  254.    /* figure out how to move the file pointer to the tagged file */
  255.  
  256.    if (on_screen(i)) {
  257.       fp_off(cw.curidx);               /* if the new file is currently */
  258.       fp_on(cw.curidx = i);            /*   displayed, just move the pointer */
  259.    } else {
  260.       cw.curidx = i;                   /* otherwise ... */
  261.       adjust_window();                 /* update entire window if t